﻿using Core.Configuration.Config;
using IconYuan.Model.DTO.Markets;
using IconYuan.Model.DTO.Products;
using IconYuan.Model.Products;

namespace IconYuan.Api.Services
{
    public class GoodsServices
    {
        public static List<GoodsBaseDto> ToGoods(List<GoodsBase> goodsList, List<PromotionDto> proList = null)
        {
            if (proList == null)
                proList = new List<PromotionDto>();
            return goodsList.Select(x => new GoodsBaseDto
            {
                goods_id = x.goods_id,
                goods_name = x.goods_name,
                goods_price_min = x.goods_price_min,
                line_price_min = x.line_price_min,
                sale_price = x.sale_price,
                sales_actual = x.sales_actual,
                sales_initial = x.sales_initial,
                stock_total = x.stock_total,
                selling_point = x.selling_point,
                points = x.points,
                shop_id = x.shop_id,
                spec_type = x.spec_type,
                category_id = x.category_id,
                create_time = x.create_time,
                price_desc = x.price_desc,
                goods_image = $"{GlobalConfig.CdnDomain}{x.goods_image}",
                is_upgrade = GlobalConfig.UpgradeCategoryId.Contains(x.category_id.ToString()) ? 1 : 0,
                promotion = proList.Find(y => y.goods_ids == x.goods_id.ToString())
            }).ToList();
        }
    }
}
